#define _CRT_SECURE_NO_WARNINGS 1

// 打印图形(右三角)
#include <stdio.h>

int main()
{
	int i = 0;
	int rem1 = 6;
	int rem2 = 8;
	for (i = 0; i <= 12; i++)
	{
		if (i < 7)
		{
			int j = 0;
			for (j = 0; j <= 12; j++)
			{
				if (i + j >= 6 && i + j <= rem1)
					printf("*");
				else
					printf(" ");
			}
				rem1 += 2;
			printf("\n");
		}
		else
		{
			int j = 0;
			for (j = 0; j <= 12; j++)
			{
				if (i + j <= 18 && i + j >= rem2)
					printf("*");
				else
					printf(" ");
			}
			rem2 += 2;
			printf("\n");
		}
	}
	return 0;
}



// 喝汽水，1瓶汽水1元，2个空瓶可以换一瓶汽水，给20元，可以多少汽水

#include <stdio.h>

int main()
{
	int money = 20;
	int sum = money / 1;
	int bottle = money / 1;
	while (1)
	{ 
		sum += bottle / 2;
		bottle = bottle / 2 + bottle % 2;
		if (bottle == 0 || bottle == 1)
			break;
	}
	printf("%d\n", sum);
	return 0;
}

#include <stdio.h>

int main()
{
	int n = 0;
	int r = 4 / 0;
	printf("%d", r);
	return 0;
}


// 交换三个数
#include <stdio.h>

int main()
{
	int a = 3;
	int b = 5;
	int temp = 0;
	temp = a;//第一步
	a = b;//第二步
	b = temp;//第三步
	return 0;
}

#include <stdio.h>

int main()
{
	int a = 3;
	int b = 5;
	a = a + b;
	b = a - b;
	a = a - b;
	return 0;
}

#include <stdio.h>

int main()
{
	int a = 3;
	int b = 5;
	printf("交换前：a=%d, b=%d\n", a, b);
	a = a ^ b;
	b = a ^ b;
	a = a ^ b;
	printf("交换后：a=%d, b=%d\n", a, b);
	return 0;
}



// 多组输入的实现

#include <stdio.h>

int main()
{
	int a = 0;
	int b = 0;
	while (scanf("%d%d", &a, &b) == 2)
	{

	}
	while (scanf("%d", &a) != EOF)
	{

	}
	while (~scanf("%d", &a))
	{

	}
	return 0;
}



// 计算一个数中二进制出现一的个数
#include <stdio.h>

int main()
{
	int count = 0;
	int n = 0;
	scanf("%d", &n);
	int i = 0;
	for (i = 0; i < 32; i++)
	{
		if (n & 1)
			count++;
		n = n >> 1;
	}
	printf("%d\n", count);
	return 0;
}


// 打印整数二进制的奇数位和偶数位

#include <stdio.h>

int main()
{
	int n = 0;
	scanf("%d", &n);
	int ret = n;
	int i = 0;
	printf("偶数位：");
	for (i = 31; i >= 1; i-=2)
	{
		printf("%d", (ret>>i) & 1);
	}

	printf("\n奇数位：");
	for (i = 30; i >= 0; i -= 2)
	{
		printf("%d", (ret >> i) & 1);
	}
	return 0;
}


// 两个整数二进制位不同个数

#include <stdio.h>

int main()
{
	int x = 0;
	int y = 0;
	scanf("%d %d", &x, &y);
	int i = 0;
	int count = 0;
	for (i = 0; i < 32; i++)
	{
		if (((x >> i) & 1) != ((y >> i) & 1))
			count++;
	}
	printf("%d\n", count);
	return 0;
}

// X形图案
#include <stdio.h>

int main()
{
	int x = 0;
	int y = 0;
	int n = 0;
	while (~scanf("%d", &n))
	{
		for (x = 0; x < n; x++)
		{
			for (y = 0; y < n; y++)
			{
				if ((x == y) || (x + y == n - 1))
					printf("*");
				else
					printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}

// BC60-带空格直角三角形图案
#include <stdio.h>

int main()
{
	int n = 0;
	int x = 0;
	int y = 0;
	while (~scanf("%d", &n))
	{
		for (x = 0; x < n; x++)
		{
			for (y = 0; y < n; y++)
			{
				if (x + y >= n - 1)
					printf("* ");
				else
					printf("  ");
			}
			printf("\n");
		}
	}
	return 0;
}




// 杨氏矩阵中查找一个数（杨氏矩阵：在一个二维数组中，一行数据从左向右是增加的，一列数据从上到下是增加的）


// 1.遍历法
#include <stdio.h>
struct Return
{
	int x;
	int y;
};
struct Return Search_Y(int (*arr)[3], int key, int row, int col)
{
	struct Return ret = {-1, -1};
	int i = 0;
	int j = 0;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			if (arr[i][j] == key)
			{
				ret.x = i;
				ret.y = j;
				return ret;
			}
		}
	}
	return ret;
}
int main()
{
	struct Return ret = { 0 };
	int arr[3][3] = { 1,2,3,4,5,6,7,8,9 };
	int key = 0;
	scanf("%d", &key);
	ret = Search_Y(arr, key, 3, 3);
	if (ret.x != -1)
		printf("%d %d\n", ret.x, ret.y);
	else
		printf("Not find the key number!\n");
	return 0;
}
 
 
// 2. 
#include <stdio.h>
struct Return
{
	int x;
	int y;
};
struct Return Search_Y(int (*arr)[3], int key, int row, int col)
{
	struct Return ret = {-1, -1};
	int x = 0;
	int y = col - 1;
	while (x < row && y >= 0)
	{
		if (key > arr[x][y])
			x++;
		else if (key < arr[x][y])
			y--;
		else
		{
			ret.x = x;
			ret.y = y;
			return ret;
		}
	}
	return ret;
}
int main()
{
	struct Return ret = { 0 };
	int arr[3][3] = { 1,2,3,4,5,6,7,8,9 };
	int key = 0;
	scanf("%d", &key);
	ret = Search_Y(arr, key, 3, 3);
	if (ret.x != -1)
		printf("%d %d\n", ret.x, ret.y);
	else
		printf("Not find the key number!\n");
	return 0;
}

// 实现一个函数，可以左旋字符串中的k个字符

#include <stdio.h>
#include <string.h>
void Str_Left_Rotation(char arr[], char ret[], int k)
{
	int len = (int)strlen(arr);
	k = k % len;
	int i = 0;
	for (i = 0; i < len; i++)
	{
		if (i - k >= 0)
			ret[i - k] = arr[i];
		else
			ret[len - k + i] = arr[i];
	}
}
int main()
{
	char arr[20] = { 0 };
	char ret[20] = { 0 };
	int k = 0;
	scanf("%s", arr);
	scanf("%d", &k);
	Str_Left_Rotation(arr, ret, k);
	puts(ret);
	return 0;
}

#include <stdio.h>
#include <string.h>

void reverse(char* left, char* right)
{
	while (left < right)
	{
		char temp = *left;
		*left = *right;
		*right = temp;
		left++;
		right--;
	}
}
void Str_Left_Rotation(char* arr, int k)
{
	int len = (int)strlen(arr);
	 //第一步：对前 k 个字母逆置
	reverse(arr, arr + k - 1);
	 //第二步：对剩余的字母逆置
	reverse(arr + k, arr + len - 1);
	 //第三步：对整体字母逆置
	reverse(arr, arr + len - 1);
}
int main()
{
	char arr[20] = { 0 };
	int k = 0;
	scanf("%s", arr);
	scanf("%d", &k);
	Str_Left_Rotation(arr, k);
	puts(arr);
	return 0;
}


// 实现一个字符串，判断给定的字符串能够由给定的字符串翻转得来
#include <stdio.h>
#include <string.h>
int Str_Isqulity(char arr1[], char arr2[])
{
	int len = (int)strlen(arr1);
	int i = 0;
	for (i = 0; i < len - 1; i++)//翻转次数
	{
		char ret[20] = { 0 };
		int j = 0;
			for (j = 0; j < len; j++)//向左翻转
			{
				if (j - i >= 0)
					ret[j - i] = arr1[j];
				else
					ret[len - i + j] = arr1[j];
			}
			if (strcmp(ret, arr2) == 0)//对比
				return 1;
	}
	return 0;
}
int main()
{
	char arr1[20] = { 0 };
	char arr2[20] = { 0 };
	scanf("%s", arr1);
	scanf("%s", arr2);
	int ret = Str_Isqulity(arr1, arr2);
	if (ret == 1)
		printf("Yes\n");
	else
		printf("NO\n");
	return 0;
}


